package csy.view.memeda.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by chengsiyuan on 2017/11/26.
 */

public class PracticePathView extends View {

    private Paint paint;
    Path path;

    public PracticePathView(Context context) {
        super(context);
    }

    public PracticePathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        path = new Path();
        //画圆，和canvas类似
//        path.addCircle(300,200,100, Path.Direction.CW);



//        path.moveTo(200,200);
//        path.lineTo(100,100);
        //rlineto 是在这个基础上移动多少像素，不是坐标
        //连接点lineto 也会连接起来
//        path.lineTo(300,0);


//        path.lineTo(100, 100);
//        //画弧线，forceMoveTo true代表是否显示和直线之间点连接线
//        path.arcTo(400, 400, 700, 700, 90, 90, true);




        //close 封闭图形   不是所有的子图形都需要使用 close() 来封闭。当需要填充图形时（即 Paint.Style 为 FILL 或 FILL_AND_STROKE），Path 会自动封闭子图形。
//        path.moveTo(200,250);
//        path.lineTo(300,250);
//        path.rLineTo(0,100);
//        path.close();



        path.addArc(300,300,400,400,145,225);
        path.arcTo(400,300,500,400,180,225,false);
        path.lineTo(400,487);
        path.close();





    }

    public PracticePathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public PracticePathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(path, paint);
    }
}
